import 'package:event/event.dart';
import 'package:flutter/material.dart';
import 'package:giwiki/src/rust/api/properties.dart';

import '../components/slider_dialog.dart';

var columnCountSetting = 0;

Event columnCountSettingChanged = Event();

Future initColumnCountSetting() async {
  columnCountSetting = await loadIntProperty(k: "columnCountSetting");
}

Future setColumnCountSetting(int value) async {
  await saveIntProperty(k: "columnCountSetting", v: value);
  columnCountSetting = value;
  columnCountSettingChanged.broadcast();
}

Future userChooseColumnCountSetting(BuildContext context) async {
  var value = await sliderDialog(
    context,
    title: const Text("选择列数(0为自动)"),
    min: 0,
    max: 10,
    value: columnCountSetting,
  );
  if (value != null) {
    await setColumnCountSetting(value);
  }
}